package com.myhexin.globalbroker.rwa.common.component.aop;

import com.myhexin.globalbroker.rwa.common.component.exception.BaseException;
import com.myhexin.globalbroker.rwa.entity.constants.RetCodeConstants;
import com.myhexin.globalbroker.rwa.interfaces.rest.vo.BaseVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @auther zhangzhonglv@myhexin.com
 * @date 2025/9/29
 */
@Slf4j
@RestControllerAdvice
public class ExceptionCatcher {

    @ExceptionHandler(Exception.class)
    public BaseVo<Void> handleException(Exception e) {
        log.error("handle exception", e);
        return BaseVo.error(RetCodeConstants.SYSTEM_ERROR, e.getMessage());
    }

    @ExceptionHandler(BaseException.class)
    public BaseVo<Void> handleBaseException(BaseException e) {
        log.error("handle exception", e);
        return BaseVo.error(e.getCode(), e.getMessage());
    }
}
